#include "timerbtn.h"
#include<QDebug>


TimerBtn::TimerBtn(QWidget *parent):QPushButton(parent),_counter(10)
{
    _timer=new QTimer(this);
    connect(_timer,&QTimer::timeout,[this](){
        _counter--;
        if(_counter<=0){
            _timer->stop();
            this->setText("获得");
            _counter=10;
            this->setEnabled(true);
            return;
        }
        this->setText(QString::number(_counter));

    });
}

TimerBtn::~TimerBtn()
{

}

void TimerBtn::mouseReleaseEvent(QMouseEvent *e)
{
    if(e->button()==Qt::LeftButton){
        qDebug()<<"get varify code";
        this->setText(QString::number(_counter));
        _timer->start(1000);
        this->setEnabled(false);
        emit clicked();
    }
    QPushButton::mouseReleaseEvent(e);
}
